using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DataAccess;
using Entity; 
namespace Business
{
    public class bPlanDetail
    {
        public static int insertPlanDetail(ePlanDetail planDetail)
        {
            DBHelper dbh = new DBHelper();

            IList<SqlParameter> paramList = new List<SqlParameter>();
            SqlParameter pr = new SqlParameter("@PlanDetailName", SqlDbType.NVarChar);
            pr.Value = planDetail.PlanDetailName;
            paramList.Add(pr);

            pr = new SqlParameter("@PlanDetailPrice", SqlDbType.Float);
            pr.Value = planDetail.PlanDetailPrice;
            paramList.Add(pr);

            pr = new SqlParameter("@PlanDetailDescription", SqlDbType.NVarChar);
            pr.Value = planDetail.PlanDetailDescription;
            paramList.Add(pr);

            pr = new SqlParameter("@planID", SqlDbType.Int);
            pr.Value = planDetail.planID;
            paramList.Add(pr);

            int r = dbh.ExecuteNonQuery("insertPlanDetail", CommandType.StoredProcedure, paramList);
            dbh.CloseConnection();
            return r;
        }

        public static int updatePlanDetail(ePlanDetail planDetail)
        {
            DBHelper dbh = new DBHelper();

            IList<SqlParameter> paramList = new List<SqlParameter>();
            SqlParameter pr = new SqlParameter("@PlanDetailID", SqlDbType.Int);
            pr.Value = planDetail.PlanDetailID;
            paramList.Add(pr);

            pr = new SqlParameter("@PlanDetailName", SqlDbType.NVarChar);
            pr.Value = planDetail.PlanDetailName;
            paramList.Add(pr);

            pr = new SqlParameter("@PlanDetailPrice", SqlDbType.Float);
            pr.Value = planDetail.PlanDetailPrice;
            paramList.Add(pr);

            pr = new SqlParameter("@PlanDetailDescription", SqlDbType.NVarChar);
            pr.Value = planDetail.PlanDetailDescription;
            paramList.Add(pr);

            pr = new SqlParameter("@planID", SqlDbType.Int);
            pr.Value = planDetail.planID;
            paramList.Add(pr);

            int r = dbh.ExecuteNonQuery("updatePlanDetail", CommandType.StoredProcedure, paramList);
            dbh.CloseConnection();
            return r;
        }

        public static int deletePlanDetail(int planDetailID)
        {
            DBHelper dbh = new DBHelper();

            IList<SqlParameter> paramList = new List<SqlParameter>();
            SqlParameter pr = new SqlParameter("@PlanDetailID", SqlDbType.Int);
            pr.Value = planDetailID;
            paramList.Add(pr);

            int r = dbh.ExecuteNonQuery("deletePlanDetail", CommandType.StoredProcedure, paramList);
            dbh.CloseConnection();
            return r;
        }


        public static DataTable getAllPlanDetail()
        {
            DBHelper dbh = new DBHelper();
            DataTable dt = dbh.ExecuteQueryDataTable("getAllPlanDetail", CommandType.StoredProcedure, new List<SqlParameter>());
            dbh.CloseConnection();
            return dt;
        }

        public static DataTable getPlanDetailByPlanID(int PlanID)
        {
            DBHelper dbh = new DBHelper();

            IList<SqlParameter> paramList = new List<SqlParameter>();

            SqlParameter pr = new SqlParameter("@planID", SqlDbType.Int);
            pr.Value = PlanID;
            paramList.Add(pr);

            DataTable dt = dbh.ExecuteQueryDataTable("getPlanDetailByPlanID", CommandType.StoredProcedure, paramList);
            dbh.CloseConnection();
            return dt;
        }
        public static ePlanDetail getPlanDetailByID(int planDetailID)
        {
            IList<SqlParameter> paramList = new List<SqlParameter>();
            SqlParameter pr = new SqlParameter("@PlanDetailID", SqlDbType.Int);
            pr.Value = planDetailID;
            paramList.Add(pr);

            IList il = bBase.LoadQueryString(typeof(ePlanDetail), "getPlanDetailByID", CommandType.StoredProcedure, paramList);
            if (il.Count > 0)
            {
                return (ePlanDetail)il[0];
            }
            else
            {
                return null;
            }
        }
    }
}
